package javawdw.picture.util;

import java.util.ArrayList;
import java.util.List;

import javawdw.picture.api.Picture;
import javawdw.picture.core.DynPicture;
import javawdw.picture.core.Frame;

public class PictureSpliter {
	private List<Frame> frames;

	public PictureSpliter(Picture picture) {
		if (picture instanceof Frame) {
			this.frames = new ArrayList<Frame>();
			Frame frame = (Frame) picture;
			frames.add(frame);
		} else if (picture instanceof DynPicture) {
			DynPicture dynPicture = (DynPicture) picture;
			this.frames = dynPicture.getFrames();
		}
	}

	public List<Frame> split() {
		return this.frames;
	}

	public static List<Frame> split(Picture picture) {
		return new PictureSpliter(picture).split();
	}

	public static Frame getFirstFrame(Picture picture) {
		PictureSpliter imageSpliter = new PictureSpliter(picture);
		List<Frame> list = imageSpliter.split();
		return (list != null && list.size() > 0) ? list.get(0) : null;
	}
}